/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2006</p>
 * <p>CreateTime: 2006-4-20 </p>
 * @author pengz
 * @version 1.0
 */

package cn.agiledata.bank.tel.util;

import cn.agiledata.bank.facade.helper.TemplateHelper;
import cn.agiledata.bank.tel.bean.TelCallBean;
import com.vnv.infrastructure.exception.IPBException;
import com.vnv.infrastructure.logic.IPBAppFactory;



public class VelocityUtil {
	
	private static TemplateHelper template ;
	
	public static TemplateHelper getTemplateHelper() throws IPBException {
		if(template == null) {
			template = (TemplateHelper) IPBAppFactory.getObj("templateHelper") ;
		}
		return template ;
	}

	/**
	 * 电话
	 * @param telBean
	 * @return
	 * @throws Exception
	 */
	public synchronized String getVelocityString(TelCallBean telBean)
	throws Exception {
		
		String content = getTemplateHelper().mergeContent(telBean.getTemplateName(), telBean.getContext()) ;
		return content ;
		/*
		Properties p = new Properties();

		ClassLoader loader = Thread.currentThread().getContextClassLoader();
		URL url = loader.getResource("/");
		String ustr =url+"";
		ustr =ustr.substring(6,ustr.length());
		ustr=ustr.substring(0,ustr.length()-8);
		ustr+="conf/templates/";
		System.err.println(ustr);

		p.put("file.resource.loader.path",
				ustr);
		// 设置velocity的输入输出编码转换
		p.put("output.encoding", "GBK");
		p.put("input.encoding", "utf-8");// 输入的编码
		VelocityEngine vengine = new VelocityEngine();
		vengine.init(p);

		Template templates = vengine.getTemplate(telBean.getTemplateName());
		VelocityContext context = new VelocityContext();
		// 把模版变量的值设置到context中

		context.put("bean", telBean.getContext());

		// 开始模版的替换
		StringWriter sw = new StringWriter();

		BufferedWriter out = new BufferedWriter(sw);

		templates.merge(context, out);

		out.flush();
		out.close();

		out = null;
		return sw.toString();
		*/

	}

}
